package com.twu.biblioteca;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * Created by sahej on 6/16/14.
 */
public class AddMovieToFile {
    static ArrayList<Movie> Movies = new ArrayList<Movie>();

    private static void initializeList() {

        Movies.add(new Movie(1, "Divergent", "Neil Burger",8, 2014));
        Movies.add(new Movie(2, "Godzilla", "Gareth Edwards",7, 2014));
        Movies.add(new Movie(3, "22 Jump Street", "Phil lorth",8, 2014));
        Movies.add(new Movie(4, "The Grand Budapest Hotel", "Wes Anderson",9, 2014));
        Movies.add(new Movie(5, "Captain America: The Winter Soldier", "Anthony Russo",9, 2014));
        Movies.add(new Movie(6, "3 Days to Kill", "McG",6, 2014));
        Movies.add(new Movie(7, "The Amazing Spider-Man 2", "Marc Webb",8, 2014));
        Movies.add(new Movie(8, "That Awkward Moment", "Tom Gormican",6,2014));
        Movies.add(new Movie(9, "Neighbors", "Nicolas Stoller",7, 2014));
        Movies.add(new Movie(10, "300: Rise of an Empire", "Noam Murro",7,2014));


    }

    public static void main(String args[]) throws Exception {
        initializeList();
        Iterator<Movie> iterator = Movies.iterator();
        try {

            FileOutputStream fout = new FileOutputStream("Movie.ser");
            ObjectOutputStream oos = new ObjectOutputStream(fout);
            while (iterator.hasNext()) {
                Movie m = iterator.next();
                oos.writeObject(m);
            }

            oos.close();
            System.out.println("Done");

        } catch (Exception ex) {
            ex.printStackTrace();
        }
        FileOutputStream fout = new FileOutputStream("CheckedMovie.ser");
        ObjectOutputStream oos = new ObjectOutputStream(fout);
        oos.close();

    }
}
